package com.th.supcom.pds.phamapply.client.widget.inpharmacyreturn;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
/**
 * 住院药房退药主面板.
 * 
 * @author yzhang
 */

public class NurseReturnMainPanel extends ContentPanel
{
    /** 退药按钮 */
    private NurseReturnButtons m_nurseReturnButtons;
    /** 退药文本域 */
    private NurseReturnFields m_nurseReturnFields;
    private NurseReturnGridPanel m_nurseReturnGridPanel;
    private NurseReturnAction m_nurseReturnAction;
    
    public NurseReturnMainPanel ()
    {
        initUI ();
        initAction ();
        initListeners ();
    }

    /**
     * 初始化UI
     */
    private void initUI ()
    {
        setHeaderVisible (false);
        setBorders (false);
        setLayout (new BorderLayout ());
        // 初始化对象
        NurseReturnQueryPanel m_nurseReturnQueryPanel;
        NurseReturnPatientPanel m_nurseReturnPatientPanel;
        m_nurseReturnButtons = new NurseReturnButtons ();
        m_nurseReturnFields = new NurseReturnFields ();
        m_nurseReturnPatientPanel = new NurseReturnPatientPanel (m_nurseReturnFields);
        m_nurseReturnQueryPanel = new NurseReturnQueryPanel (m_nurseReturnFields, m_nurseReturnButtons);
        m_nurseReturnGridPanel = new NurseReturnGridPanel ();

        LayoutContainer northPanelContainer = new LayoutContainer ();
        northPanelContainer.setLayout (new RowLayout (Orientation.VERTICAL));
        northPanelContainer.add (m_nurseReturnQueryPanel, new RowData (1, 0.42, new Margins (0)));
        northPanelContainer.add (m_nurseReturnPatientPanel, new RowData (1, 0.56, new Margins (0)));
        // 设置布局和大小
        BorderLayoutData northData = new BorderLayoutData (LayoutRegion.NORTH, 140);
        northData.setMargins (new Margins (4, 4, 8, 4));
        BorderLayoutData centerData = new BorderLayoutData (LayoutRegion.CENTER);
        centerData.setMargins (new Margins (0, 4, 4, 4));

        add (northPanelContainer, northData);
        add (m_nurseReturnGridPanel, centerData);
        // 初始化下部按钮
        ContentPanel bottomContainer = new ContentPanel ();
        bottomContainer.setHeaderVisible (false);
        bottomContainer.setButtonAlign (HorizontalAlignment.CENTER);
        bottomContainer.addButton (m_nurseReturnButtons.getComfirmBtn ());
        bottomContainer.addButton (m_nurseReturnButtons.getClearBtn ());
        setBottomComponent (bottomContainer);
        m_nurseReturnFields.getBedNoField ().focus ();
    }

    /**
     * 初始化事件
     */
    private void initAction ()
    {
        m_nurseReturnAction = new NurseReturnAction ();
        m_nurseReturnAction.setNurseReturnFields (m_nurseReturnFields);
        m_nurseReturnAction.setMainPanel (this);
        m_nurseReturnAction.setNurseReturnButtons (m_nurseReturnButtons);
        m_nurseReturnAction.setNurseReturnGridPanel (m_nurseReturnGridPanel);
    }

    /**
     * 初始化事件监听
     */
    private void initListeners ()
    {
        /** 门诊退药Listener */
        NurseReturnListener nurseReturnListener = new NurseReturnListener ();
        nurseReturnListener.setNurseReturnButtons (m_nurseReturnButtons);
        nurseReturnListener.setNurseReturnFields (m_nurseReturnFields);
        nurseReturnListener.setKeyNavComponent (this);
        nurseReturnListener.setNurseReturnAction (m_nurseReturnAction);
        nurseReturnListener.initListeners ();
    }
   

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";
    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";
}